/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-07-14
 * Time: 22:20
 */
//String类提供的查找方法主要有三类：
   /* 1.指定查找
    2.从前往后找
    3.从后往前找*/
public class Main_3 {
    public static void main(String[] args) {
        String s1 = "abcdabcdef";
        char ch = s1.charAt(1);  //charAt方法查找指定下标的字符
        System.out.println(ch);
        System.out.println("==========");
        int num = s1.indexOf('b'); //indexOf方法从前往后查找某个字符第一次出现的下标
        System.out.println(num);
        int num1 = s1.indexOf('b',2); //指定从某个位置开始找
        System.out.println(num1);
        int num2 = s1.indexOf("abc");  //也可以查找字符串
        System.out.println(num2);
        int num3 = s1.indexOf("abc",2);
        System.out.println(num3);
        System.out.println("==========");
        int num4 = s1.lastIndexOf('a'); //lastIndexOf方法从后往前查找某个字符第一次出现的下标
        System.out.println(num4);
        int num5 = s1.lastIndexOf('a',3); //指定从某个位置开始找
        System.out.println(num5);
        int num6 = s1.lastIndexOf("abc"); //也可以查找字符串
        System.out.println(num6);
        int num7 = s1.lastIndexOf("abc",3);
        System.out.println(num7);
    }
}
